package com.example.baitapsqlite;

import com.ducbt.model.ListFileDTO;
import com.ducbt.model.ListFileDatabase;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	EditText etFileName, etTitle;
	CheckBox cbCheck;
	private ListFileDatabase datasource;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        etFileName = (EditText)findViewById(R.id.etFileName);
        etTitle = (EditText)findViewById(R.id.etTitle);
        cbCheck = (CheckBox)findViewById(R.id.cbCheck);
        datasource = new ListFileDatabase(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void fInsert(View v){
    	if(cbCheck.isChecked()==true){
    		Toast.makeText(this, "Check = 1", Toast.LENGTH_SHORT).show();
    	}
    	ListFileDTO listFile = new ListFileDTO(etFileName.getText().toString(), cbCheck.isChecked(), etTitle.getText().toString());
    	datasource.open();
		if(datasource.createRecord(listFile)){
			Toast.makeText(this, "Luu ban ghi thanh cong", Toast.LENGTH_SHORT).show();
		}
		datasource.close();
    }
}
